package com.brillilab.starter.controller.aio.method;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.brillilab.common.entity.ResponseVo;
import com.brillilab.domain.enums.lab.LabMemberPowerEnum;
import com.brillilab.domain.vo.method.MethodContrastChartListVo;
import com.brillilab.domain.vo.method.MethodContrastVo;
import com.brillilab.domain.vo.user.UserInfoVo;
import com.brillilab.service.core.method.IMethodService;
import com.brillilab.service.logic.user.UsersLogic;
import com.brillilab.starter.constant.StarterConstant;
import com.brillilab.starter.handler.RequestPower;

/**
 * 成员方法对比
 * 
 * @author lj
 *
 */
@RestController
@RequestMapping("/api/method/contrast")
public class MethodContrastController {
	@Autowired
	private IMethodService methodService;
	@Autowired
	private UsersLogic usersLogic;

	/**
	 * 成员方法统计对比列表
	 * 
	 * @param token
	 * @return
	 */
	@RequestPower(LabMemberPowerEnum.method)
	@GetMapping("/chartList")
	public ResponseVo chartList(@RequestHeader(value = StarterConstant.TOKEN) String token) {
		UserInfoVo userVo = usersLogic.getUserByToken(token);
		List<MethodContrastVo> chartList = methodService.getMethodContrastChartList(userVo.getLabId(), null);
		return ResponseVo.success(chartList);
	}

	/**
	 * 成员方法统计对比详情
	 * 
	 * @param token
	 * @param sortType: 1-调用次（默认）,2-成功率,3-成员
	 * @param sort 数排序：0-升序（默认），1-降序
	 * @return
	 */
	@RequestPower(LabMemberPowerEnum.method)
	@GetMapping("/chartInfo")
	public ResponseVo chartInfo(Long firstTypeId, String secondTypeName, Integer sortType, Integer sort, String methodTypeName,
			@RequestHeader(value = StarterConstant.TOKEN) String token) {
		UserInfoVo userVo = usersLogic.getUserByToken(token);
		MethodContrastChartListVo chartInfo = methodService.getMethodContrastChart(userVo.getLabId(), firstTypeId,
				secondTypeName, methodTypeName, sortType, sort);
		return ResponseVo.success(chartInfo);
	}

}
